require 'watir'
include Watir
require 'test/unit'
require '../watir.config.rb'
require '../resources/functions.rb'
require 'win32ole'
require 'win32/process'

class TC_Media_test < Test::Unit::TestCase
   
    def startup
      $Url1 ='http://www.freefoto.com/images/46/08/46_08_4---Clouds_web.jpg?&k=Clouds'
      $Url2 ='http://www.freefoto.com/images/12/56/12_56_2---Iris_web.jpg?&k=Iris'
      $Url3 ='http://www.freefoto.com/images/19/07/19_07_83---Autumn-Colour_web.jpg?&k=Autumn+Colour'
      $Url4 ='http://www.freefoto.com/images/01/47/01_47_29---Common-Buzzard_web.jpg?&k=Common+Buzzard'
      $GroupName= 'Media Group'
      $GroupDescription = 'This is to test media group'
      $MediaGalleryName = 'Gallery1'
      $AppKey = 'MediaAppKey'
      $Owners = 'User1'
      $Subject1 ='mediaFile1'
      $Description1 = 'This is to test media file'
      $Tag1 = 'first,automated,media'
      $Subject2 ='mediaFile2'
      $Description2 ='This is to test media file 2'
      $Tag2 = 'second,mediafile'
      $Subject3 ='mediaFile3'
      $Description3 = 'This is to test media file 3'
      $Tag3 = 'third,gallery'
      $Subject4 ='mediaFile4'
      $Description4 = 'This is to test media file 4'
      $Tag4 = 'fourth,mediagallery'
      $Subject3Edit = $Subject3 +'-Edit'
      $Description3Edit = $Description3 +'-Edit'
      $Tag3Edit = $Tag3 +',Edit'
      $UserName = 'User1'
      $UserPassword = 'pass123'
      $UserEmail = 'user@user.com'
      $Comments ='Testing Media Comments'
      @@ie = Watir::IE.start($SITE_URL)
    end
    
    def ie
      if defined? @@ie
        @@ie
      else
        startup
      end
    end
    
    def test_0000
        require 'win32/process'
        $pid = Process.create(
        :app_name      => 'ruby ../resources/clickers.rb',
        :creation_flags  => Process::DETACHED_PROCESS
        ).process_id
      end  
      
    
    def test_01_verifyHomeText
        assert(ie.contains_text(/Community Server/))		
      end
 
    def test_02_verifyLoginLinksExist
      if !(ie.link(:text, 'Sign in').exists?)
        ie.goto($SITE_URL + 'logout.aspx')
        ie.refresh
        ie.goto($SITE_URL)
        ie.refresh
      end
	  end

    def test_03_navigateToLogin
        ie.link(:text, 'Sign in').click
        assert(ie.contains_text("Sign in name"))
      end

	  def test_04_populateLoginForm
        ie.text_field(:id, /username$/).value = $ADMIN_USER
        assert(ie.text_field(:id, /username$/).verify_contains($ADMIN_USER))
        ie.text_field(:id, /password$/).value = $ADMIN_PASSWORD
        assert(ie.text_field(:id, /password$/).verify_contains($ADMIN_PASSWORD))
      end

    def test_05_submitLoginForm
        if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
        test_01_verifyHomeText
      end

    def test_06_verifyControlPanel
        assert(ie.link(:text, /Control Panel/).exists?)
        ie.link(:text, /Control Panel/).click
        assert(ie.contains_text(/Announcements/))
        assert(ie.link(:text, /System Administration/).exists?)
        ie.link(:text, /System Administration/).click
        assert(ie.contains_text(/Announcements/))
      end

    def test_07_verifyControlPanelLinks
        assert_equal $SITE_URL + 'controlpanel/', ie.link(:text, 'Dashboard').href
        assert_equal $SITE_URL + 'controlpanel/setup.aspx', ie.link(:text, 'Administration').href
        assert_equal $SITE_URL + 'controlpanel/BlogAdmin/', ie.link(:text, 'Blog Administration').href
        assert_equal $SITE_URL + 'controlpanel/MediaGalleryAdmin/', ie.link(:text, 'Media Galleries Administration').href
        assert_equal $SITE_URL + 'controlpanel/Forums/', ie.link(:text, 'Forum Administration').href
        assert_equal $SITE_URL + 'controlpanel/HubAdmin/', ie.link(:text, 'Group Administration').href
        assert_equal $SITE_URL + 'controlpanel/Membership/membersearch.aspx?SelectedNavItem=BrowseMembers', ie.link(:text, 'Membership Administration').href
        assert_equal $SITE_URL + 'controlpanel/Settings/default.aspx', ie.link(:text, 'Site Administration').href
      end

    def test_08_navigateToMediaAdministration
        ie.goto($SITE_URL + 'controlpanel/MediaGalleryAdmin/')
        assert(ie.contains_text('Media Gallery Administration'))      
      end
 
    def test_09_verifyLinksExist
      # Make sure that all of the links exist
        assert(ie.link(:text, 'Log Out').exists?)
        assert(ie.link(:text, 'Help').exists?)
        assert(ie.link(:text, 'Go to Site').exists?)
        assert(ie.link(:text, 'Dashboard').exists?)
        assert(ie.link(:text, 'Administration').exists?)
        assert(ie.link(:text, 'Media Gallery Administration').exists?)
        assert(ie.link(:text, 'Telligent').exists?)
      end

    def test_10_navigateToCreateMediaGroup 
        ie.goto($SITE_URL +'controlpanel/MediaGalleryAdmin/Groups.aspx')
        assert(ie.button(:value,'Add New Group').exists?)
        ie.button(:value,'Add New Group').click
      end
  
    def test_11_navigateToCreateGroup
      sleep 3
      assert(ie.text_field(:id,'ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_GroupName').exists?)
      sleep 2
      ie.text_field(:id,'ctl00_ctl00_ctl00_OuterTaskRegion_TaskRegion_TaskRegion_TaskRegion_GroupName').value =$GroupName
      sleep 2
      assert(ie.text_field(:id,/GroupDesc$/).exists?)
      ie.text_field(:id,/GroupDesc$/).value =$GroupDescription
      assert(ie.button(:id,/Save$/).exists?)
      ie.button(:id,/Save$/).click
      end

    def test_12_createNewUser
        ie.goto($SITE_URL +'controlpanel/membership/UserAdd.aspx')
        assert(ie.text_field(:id,/username$/).exists?)
        ie.text_field(:id,/username$/).value = $UserName
        assert(ie.text_field(:id,/password$/).exists?)
        ie.text_field(:id,/password$/).value = $UserPassword
        password=ie.text_field(:id,/password$/).value
        assert(ie.text_field(:id,/password2$/).exists?)
        ie.text_field(:id,/password2$/).value =password
        assert(ie.text_field(:id,/email$/).exists?)
        ie.text_field(:id,/email$/).value = $UserEmail
        assert(ie.select_list(:id,/timezone$/).exists?)
        ie.select_list(:id,/timezone$/).select('(GMT +05:00) Islamabad, Karachi, Tashkent')
        assert(ie.button(:name,/createButton$/).exists?)
        ie.button(:name,/createButton$/).click
      end

    def test_13_navigateToCreateMediaGallery
        sleep 3
        ie.goto($SITE_URL +'controlpanel/MediaGalleryAdmin/CreateEditMediaGallery.aspx')
        assert(ie.text_field(:id,/Name$/).exists?)
        ie.text_field(:id,/Name$/).value =$MediaGalleryName
        assert(ie.text_field(:id,/AppKey$/).exists?)
        ie.text_field(:id,/AppKey$/).value = $AppKey
        $key =ie.text_field(:id,/AppKey$/).value
        $key1 =$key.downcase
        assert(ie.select_list(:id,/AdminGroupList$/).exists?)
        ie.select_list(:id,/AdminGroupList$/).select($GroupName)
        assert(ie.radio(:id,/ynIsActive_0$/).exists?)
         assert(ie.radio(:id,/ynIsActive_1$/).exists?)
        ie.radio(:id,/ynIsActive_0$/).set
        assert(ie.radio(:id,/ynIsSearchable_0$/).exists?)
         assert(ie.radio(:id,/ynIsSearchable_1$/).exists?)
        ie.radio(:id,/ynIsSearchable_0$/).set
        assert(ie.text_field(:id,/Owners_ctl00$/).exists?)
        ie.text_field(:id,/Owners_ctl00$/).value =$Owners
        assert(ie.select_list(:id,/DefaultLanguage$/).exists?)
        ie.select_list(:id,/DefaultLanguage$/).select('English')
        assert(ie.button(:id,/SaveButton$/).exists?)
        ie.button(:id,/SaveButton$/).click
      end

    def test_14_navigateToUploadMediaFiles
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        ie.text_field(:id, /username$/).value = $UserName
        ie.text_field(:id, /password$/).value = $UserPassword
        if(ie.button(:id, /loginButton$/).exists?)
          ie.button(:id, /loginButton$/).click
        else
        ie.link(:id, /loginButton$/).click
        end
        sleep 2
        ie.goto($SITE_URL+'media/')
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 2
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 2
        assert(ie.link(:text,'Upload').exists?)
        ie.link(:text,'Upload').click
        sleep 2
        if(ie.button(:value,'Specify File/URL').exists?)
        ie.button(:value,'Specify File/URL').click
        else 
        ie.link(:text,'Specify File/URL').click
        end
        sleep 5
        assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
        ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
        assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
        ie.frame(:index,2).text_field(:id,/Url$/).set($Url1)
        if(ie.frame(:index,2).button(:id,/Save$/).exists?)
        ie.frame(:index,2).button(:id,/Save$/).click
        else
        ie.frame(:index,2).link(:id,/Save$/).click
        end
        sleep 2
        assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
        ie.text_field(:id,/MediaGalleryPostName$/).set($Subject1)
        sleep 2
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$Description1+"')")
        sleep 2
        assert(ie.text_field(:id,/Tags$/).exists?)
        ie.text_field(:id,/Tags$/).value=$Tag1
        # Preview
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.GetTabAtIndex(1))")
        sleep 5
        assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
        ie.button(:id,/MediaGalleryPostSave$/).click
        sleep 2
        # File 2
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 2
        assert(ie.link(:text,'Upload').exists?)
        ie.link(:text,'Upload').click
        sleep 2
        if(ie.button(:value,'Specify File/URL').exists?)
        ie.button(:value,'Specify File/URL').click
        else 
        ie.link(:text,'Specify File/URL').click
        end
        sleep 5
        assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
        ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
        assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
        ie.frame(:index,2).text_field(:id,/Url$/).set($Url2)
        if(ie.frame(:index,2).button(:id,/Save$/).exists?)
        ie.frame(:index,2).button(:id,/Save$/).click
        else
        ie.frame(:index,2).link(:id,/Save$/).click
        end
        sleep 2
        assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
        ie.text_field(:id,/MediaGalleryPostName$/).set($Subject2)
        sleep 2
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$Description2+"')")
        sleep 2
        assert(ie.text_field(:id,/Tags$/).exists?)
        ie.text_field(:id,/Tags$/).value=$Tag2
        # Preview
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.GetTabAtIndex(1))")
        sleep 5
        assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
        ie.button(:id,/MediaGalleryPostSave$/).click
        sleep 2
        # File 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 2
        assert(ie.link(:text,'Upload').exists?)
        ie.link(:text,'Upload').click
        sleep 2
        if(ie.button(:value,'Specify File/URL').exists?)
        ie.button(:value,'Specify File/URL').click
        else 
        ie.link(:text,'Specify File/URL').click
        end
        sleep 5
        assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
        ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
        assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
        ie.frame(:index,2).text_field(:id,/Url$/).set($Url3)
        if(ie.frame(:index,2).button(:id,/Save$/).exists?)
        ie.frame(:index,2).button(:id,/Save$/).click
        else
        ie.frame(:index,2).link(:id,/Save$/).click
        end
        sleep 2
        assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
        ie.text_field(:id,/MediaGalleryPostName$/).set($Subject3)
        sleep 2
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$Description3+"')")
        sleep 2
        assert(ie.text_field(:id,/Tags$/).exists?)
        ie.text_field(:id,/Tags$/).value=$Tag3
        # Preview
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.GetTabAtIndex(1))")
         sleep 5
        assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
        ie.button(:id,/MediaGalleryPostSave$/).click
        sleep 2
        # File 4
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 2
        assert(ie.link(:text,'Upload').exists?)
        ie.link(:text,'Upload').click
        sleep 2
        if(ie.button(:value,'Specify File/URL').exists?)
        ie.button(:value,'Specify File/URL').click
        else 
        ie.link(:text,'Specify File/URL').click
        end
        sleep 5
        assert(ie.frame(:index,2).radio(:id,/LinkToUrl$/).exists?)
        ie.frame(:index,2).radio(:id,/LinkToUrl$/).set
        assert(ie.frame(:index,2).text_field(:id,/Url$/).exists?)
        ie.frame(:index,2).text_field(:id,/Url$/).set($Url4)
        if(ie.frame(:index,2).button(:id,/Save$/).exists?)
        ie.frame(:index,2).button(:id,/Save$/).click
        else
        ie.frame(:index,2).link(:id,/Save$/).click
        end
        sleep 2
        assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
        ie.text_field(:id,/MediaGalleryPostName$/).set($Subject4)
        sleep 2
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$Description4+"')")
        sleep 2
        assert(ie.text_field(:id,/Tags$/).exists?)
        ie.text_field(:id,/Tags$/).value=$Tag4
        # Preview
        ie.ie.Document.parentWindow.execScript("ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.SelectTab(ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_EditorTabs.GetTabAtIndex(1))")
        sleep 5
        assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
        ie.button(:id,/MediaGalleryPostSave$/).click
        sleep 2
      end

    def test_15_editMediaFiles
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        assert(ie.link(:text, $Subject3).exists?)
        ie.link(:text, $Subject3).click
        assert(ie.link(:href,/edit.aspx$/).exists?)
        ie.link(:href,/edit.aspx$/).click
        assert(ie.text_field(:id,/MediaGalleryPostName$/).exists?)
        ie.text_field(:id,/MediaGalleryPostName$/).set($Subject3Edit)
        sleep 2
        ie.ie.Document.ParentWindow.execscript("tinyMCE.get('ctl00_ctl00_bcr_bcr_MediaGalleryPostForm_ctl05_MediaGalleryPostDescription_ctl00_Editor').execCommand('mceSetContent', false,'"+$Description3Edit+"')")
        sleep 2
        assert(ie.text_field(:id,/Tags$/).exists?)
        ie.text_field(:id,/Tags$/).value=$Tag3Edit
        assert(ie.button(:id,/MediaGalleryPostSave$/).exists?)
        ie.button(:id,/MediaGalleryPostSave$/).click
        sleep 3 
      end

    def test_16_navigateToMediaFile
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        test_04_populateLoginForm
        test_05_submitLoginForm
        ie.goto($SITE_URL+'media/')
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 4 
        # View Slide Show
        assert(ie.link(:text, 'View Slideshow').exists?)
        ie.link(:text, 'View Slideshow').click  
        sleep 30
        ie.goto($SITE_URL+'media/')
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 3
        assert(ie.link(:text, $Subject3Edit).exists?)
        ie.link(:text, $Subject3Edit).click  
        sleep 3
        # Add file
        assert(ie.link(:text, 'Add file to favorites').exists?)
        ie.link(:text, 'Add file to favorites').click 
        sleep 2
        assert(ie.link(:text, 'Add gallery to favs').exists?)
        ie.link(:text, 'Add gallery to favs').click 
        sleep 2
        # Comment 
        assert(ie.text_field(:id,/CommentBody$/).exists?)
        ie.text_field(:id,/CommentBody$/).set($Comments)
        if(ie.button(:id,/CommentSubmit$/).exists?)
        ie.button(:id,/CommentSubmit$/).click
        else
        ie.link(:id,/CommentSubmit$/).click
        end
        sleep 3
        # Download
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 3
        assert(ie.link(:text, $Subject1).exists?)
        ie.link(:text, $Subject1).click 
        sleep 3
        assert(ie.link(:text,'Download').exists?)
        ie.link(:text,'Download').click
        sleep 2
      end
      
    def test_17_deleteMediaFiles
        test_02_verifyLoginLinksExist
        test_03_navigateToLogin
        test_04_populateLoginForm
        test_05_submitLoginForm
        ie.goto($SITE_URL+'media/')
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 3
        assert(ie.link(:text, $Subject1).exists?)
        ie.link(:text, $Subject1).click  
        sleep 2
        assert(ie.link(:text,'Delete').exists?)
        ie.link(:text,'Delete').click  
        assert(ie.button(:id,/MediaGalleryPostDelete$/).exists?)
        ie.button(:id,/MediaGalleryPostDelete$/).click 
        sleep 3
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 3
        assert(ie.link(:text, $Subject2).exists?)
        ie.link(:text, $Subject2).click  
        sleep 2
        assert(ie.link(:text,'Delete').exists?)
        ie.link(:text,'Delete').click  
        sleep 3
        assert(ie.button(:id,/MediaGalleryPostDelete$/).exists?)
        ie.button(:id,/MediaGalleryPostDelete$/).click 
        sleep 3
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 3
        assert(ie.link(:text, $Subject3Edit).exists?)
        ie.link(:text, $Subject3Edit).click  
        sleep 2
        assert(ie.link(:text,'Delete').exists?)
        ie.link(:text,'Delete').click  
        sleep 3
        assert(ie.button(:id,/MediaGalleryPostDelete$/).exists?)
        ie.button(:id,/MediaGalleryPostDelete$/).click 
        sleep 3
        assert(ie.link(:text, $GroupName).exists?)
        ie.link(:text, $GroupName).click
        sleep 3
        assert(ie.link(:text, $MediaGalleryName).exists?)
        ie.link(:text, $MediaGalleryName).click
        sleep 3
        assert(ie.link(:text, $Subject4).exists?)
        ie.link(:text, $Subject4).click  
        sleep 2
        assert(ie.link(:text,'Delete').exists?)
        ie.link(:text,'Delete').click  
        sleep 3
        assert(ie.button(:id,/MediaGalleryPostDelete$/).exists?)
        ie.button(:id,/MediaGalleryPostDelete$/).click 
      end
      
    def test_18_DeleteMediaGallery
        ie.goto($SITE_URL+'controlpanel/MediaGalleryAdmin/MediaGalleries.aspx')
        sleep 2
        assert(ie.link(:text,'All').exists?)
        ie.link(:text,'All').click
        sleep 2
        assert(ie.table(:id,'BlogLists').exists?)
        table1 = ie.table(:id,'BlogLists')
        rowcount = table1.row_count
        rowcount1 =1
        ok = 0
        while rowcount1<=rowcount
            if (table1[rowcount1][1].link(:text,$key1).exists?)
              ok =1
               sleep 5
               table1[rowcount1][6].button(:value,'Delete' ).click
               break
            end   
         rowcount1=rowcount1+1
        end
      end 
      
    def test_19_DeleteMediaGroup
        ie.goto($SITE_URL+'controlpanel/MediaGalleryAdmin/Groups.aspx')
        assert(ie.table(:id,'GroupLists').exists?)
        table2 = ie.table(:id,'GroupLists')
        rows = table2.row_count
        rowcount2 =1
        ok = 0
        while rowcount2<=rows
            if (table2[rowcount2][1].link(:text,$GroupName).exists?)
              ok =1
               sleep 5
               table2[rowcount2][3].button(:value,'Delete' ).click
               break
            end   
         rowcount2=rowcount2+1
        end
      end
      
     def  test_20_searchUser
        ie.goto($SITE_URL +'controlpanel/membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
        assert(ie.text_field(:id,/searchText$/).exists?)
        ie.text_field(:id,/searchText$/).value ="*"
        assert(ie.select_list(:name,/PageList$/).exists?)
        ie.select_list(:name,/PageList$/).select('10')
        sleep 3
        assert(ie.button(:id,/searchButton$/).exists?)
        sleep 2
        ie.button(:id,/searchButton$/).click
      end

    def test_21_navigateToDeleteUser
        sleep 5
        table1 = ie.table(:index, 6)
        rowcount = table1.row_count
        rowcount1 =1
        ok =0
        while rowcount1<=rowcount
            if (table1[rowcount1][1].link(:text,$UserName).exists?)
              ok =1
               sleep 5
               table1[rowcount1][5].button(:value, 'Delete').click
               sleep 3
               break
             end   
         rowcount1=rowcount1+1
        end
       if(ok ==0)
         sleep 5
         ie.link(:text,'Next >').click
         sleep 5
         test_21_navigateToDeleteUser
       end
       sleep 5
       assert(ie.frame(:index,1).radio(:id,/AssignToAnonymous$/).exists?)
       ie.frame(:index,1).radio(:id,/AssignToAnonymous$/).set
       sleep 3
       assert(ie.frame(:index,1).button(:id,/DeleteUserButton$/).exists?)
       sleep 3
       ie.frame(:index,1).button(:id,/DeleteUserButton$/).click
       sleep 5
       ie.goto($SITE_URL +'controlpanel/membership/membersearch.aspx?SelectedNavItem=BrowseMembers')
       assert(ie.text_field(:id,/searchText$/).exists?)
       ie.text_field(:id,/searchText$/).value ="*"
       sleep 3
       assert(ie.button(:id,/searchButton$/).exists?)
       sleep 2
       ie.button(:id,/searchButton$/).click  
      if(ie.link(:text,$UserName).exists?)
        puts 'User Not Deleted'
      end  
    end
      
    def test_99_Exit
        ie.close
      end

end
    